﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenExpressApp.Module.WPF
{
    public static class DefaultViewCreator
    {
        /// <summary>
        /// 第一个参数Type：业务对象类型
        /// 第二个参数Type：注册生成WPFObjectView类型
        /// </summary>
        private static Dictionary<Type, ICreateDefaultView> _creatorMap = new Dictionary<Type, ICreateDefaultView>();

        public static void Register(Type boType, ICreateDefaultView creatorType)
        {
            _creatorMap.Add(boType, creatorType);
        }

        public static WPFObjectView Create(Type type)
        {
            foreach (var item in _creatorMap)
            {
                if (item.Key.IsAssignableFrom(type))
                    return item.Value.CreateView(type);
            }
            return null;
        }
    }

    public interface ICreateDefaultView
    {
        WPFObjectView CreateView(Type boType);
    }
}
